﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using HNCDataSetTableAdapters;
using System.Web.Routing;

public partial class UserControl_content_news : System.Web.UI.UserControl
{
    CategoryTableAdapter cate = new CategoryTableAdapter();
    ProductsTableAdapter pro = new ProductsTableAdapter();
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            //if (HttpContext.Current.Request.RequestContext.RouteData.Values["CateID"].ToString() != "all")
            //{
            //int CateID = int.Parse(HttpContext.Current.Request.RequestContext.RouteData.Values["CateID"].ToString());
            DataView dv = (DataView)pro.GetProductByCateID(4).DefaultView;
            CollectionPager1.PageSize = 12;
            CollectionPager1.DataSource = dv;
            CollectionPager1.BindToControl = rptProduct;
            rptProduct.DataSource = CollectionPager1.DataSourcePaged;
            rptProduct.DataBind();
            //    ltrTooltip.Text = loadTooltip1();
            //}
            //else
            //{
            //    DataView dv = (DataView)pro.GetByNews().DefaultView;
            //    CollectionPager1.PageSize = 9;
            //    CollectionPager1.DataSource = dv;
            //    CollectionPager1.BindToControl = rptProduct;
            //    rptProduct.DataSource = CollectionPager1.DataSourcePaged;
            //    rptProduct.DataBind();
            //    ltrTooltip.Text = loadTooltip2();
            //}
        }
    }

    public string loadTooltip1()
    {
        string tem = "";
        int CateID = int.Parse(HttpContext.Current.Request.RequestContext.RouteData.Values["CateID"].ToString());
        DataTable dt = pro.GetProductByCateID(CateID);
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            string ProductID = dt.Rows[i]["ProductID"].ToString();
            string Title = dt.Rows[i]["Title"].ToString();
            string Image = dt.Rows[i]["Image"].ToString();
            tem += @"<div id=" + ProductID + @" class='atip'>
                                    <img width='500px' src='UserUploads/Product/" + Image + @"' />
                                </div>";
        }
        return tem;
    }

    public string loadTooltip2()
    {
        string tem = "";
        DataTable dt = pro.GetByNews();
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            string ProductID = dt.Rows[i]["ProductID"].ToString();
            string Title = dt.Rows[i]["Title"].ToString();
            string Image = dt.Rows[i]["Image"].ToString();
            tem += @"<div id=" + ProductID + @" class='atip'>
                                    <img width='500px' src='UserUploads/Product/" + Image + @"' />
                                </div>";
        }
        return tem;
    }
}